package net.huashitong.log.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.log.dao.LogMessageDao;
import net.huashitong.log.entity.LogMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogMessageService extends StringPKService<LogMessage> {

    @Autowired
    private LogMessageDao dao;
    @Autowired
    private SysTableService tableService;

    @Override
    protected BaseDao<LogMessage, String> getDao() {
        return dao;
    }

    @Override
    protected void beforeSave(LogMessage obj) {
        obj.setSysId(tableService.updateMaxSysId("t_log_message", null));
    }

    public void saveLogMessage(String operator,
                               String IP,
                               String id,
                               String operation,
                               String table,
                               String detail,
                               String originalValue,
                               String finalValue) {
        LogMessage logMessage = new LogMessage();
        logMessage.setOperator(operator);
        logMessage.setIp(IP);
        logMessage.setId(id);
        logMessage.setOperation(operation);
        logMessage.setZdTable(table);
        logMessage.setDetail(detail);
        logMessage.setOriginalValue(originalValue);
        logMessage.setFinalValue(finalValue);
        save(logMessage);
    }

}
